import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:leader_help/utils/util.dart';
import '../index.dart';

class ComListTabBar extends GetView<ComListController> {
  const ComListTabBar({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ComListController>(
      builder: (_) => Container(
        color: Colors.white,
        height: 44.r,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: [1, 2, 3, 4]
              .asMap()
              .map(
                (key, value) => MapEntry(
                  key,
                  getItem(
                    text: _getText(key),
                    isActive: controller.state.activeIndex == key,
                    callback: () => controller.actionMenuTypes(key),
                  ),
                ),
              )
              .values
              .toList(),
        ),
      ),
    );
  }

  String _getText(int index) {
    switch (index) {
      case 0:
        return controller.state.comTypes[controller.state.selectComTypeIndex];
      case 1:
        return controller.state.selectedMod.areaItem?.name ?? '河南全省';
      case 2:
        return controller.state.industrySelectedMod.item?.name ?? '所有行业';
      case 3:
        return controller.state.scopes[controller.state.selectScopeIndex];
      default:
        return '';
    }
  }

  Widget getItem({
    required String text,
    bool isActive = false,
    VoidCallback? callback,
  }) {
    return InkWell(
      onTap: callback,
      child: Container(
        alignment: Alignment.center,
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Container(
              constraints: BoxConstraints(maxWidth: (Get.width - 30.r) / 4),
              child: Text(
                text,
                overflow: TextOverflow.ellipsis,
                maxLines: 1,
                style: pfMediumStyle(
                    color: isActive ? ColorsUtil.red : ColorsUtil.title,
                    fontSize: 14.sp),
              ),
            ),
            Icon(
              isActive ? Icons.arrow_drop_up : Icons.arrow_drop_down,
              color: isActive ? ColorsUtil.red : ColorsUtil.content,
              size: 20.r,
            )
          ],
        ),
      ),
    );
  }
}
